<template>
	<!-- 头像、用户名 -->
	<view>
		<!-- 开启消息提示 -->
		<u-toast ref="uToast" />
		<view class="u-flex user-box u-p-l-30 u-p-r-20 u-p-b-30">
			
			<view class="u-flex-1">
				<view class="u-font-18 u-p-b-20 u-m-l-10">{{real_name}}</view>
				<view class="u-font-14">{{welcome}}</view>
			</view>
			<!-- 头像 -->
			<view class="u-m-r-10 u-m-t-25"  @click="enterLogin">
				<u-avatar :src="pic" size="135"></u-avatar>
				
			</view>
		</view>
		<!-- 功能列表 -->
		<view class="u-m-t-1">
			<u-cell-group>
				<u-cell-item class="u-p-b-30 " icon="order" title="我的附件" @click="enterMyResume"></u-cell-item>
				<u-cell-item class="u-p-b-30" icon="bookmark" title="附件简历" @click="enterResume">上传附件</u-cell-item>
				<u-cell-item icon="integral" title="投递反馈" @click="enterDeliveryFeedback"></u-cell-item>
				<u-cell-item icon="star" title="我的收藏" @click="enterCollection" ></u-cell-item>
				<u-cell-item icon="coupon" title="求职状态" @click="jobStatusSelectShow=true" >{{jobStatus}}</u-cell-item>
				<u-cell-item icon="heart" title="意见反馈" @click="enterIdea"></u-cell-item>
			</u-cell-group>
		</view>
		<view class="u-m-t-1">
			<u-cell-group>
				<u-cell-item icon="setting" title="个人设置" @click="enterSetMyself"></u-cell-item>
			</u-cell-group>
		</view>
		<!-- 退出登录 -->
	    <view class="signOut" @click="signOut">退出登录</view>
		<!-- 消息提示 -->
		<u-modal v-model="show"  :show-cancel-button="true"  @confirm="confirm"  :content="content" :show-title="true"></u-modal>
		<!-- 求职状态选择框-->
		<u-select v-model="jobStatusSelectShow" :list="jobStatuslist" @confirm="jobStatusSelectShowConfirm"></u-select>
	
	</view>
	
</template>

<script>
	export default {
		name:'my',
		data() {
			return {
				pic:'../../static/icon/KHCFDC_头像 2.png',
				//控制退出消息提示
				show:false,
				content:'确认退出当前账号',
				real_name:'未登录/注册',
				welcome:'点击头像进行登录或者注册',
				//求职状态选择框显示
				jobStatusSelectShow:false,
				// 求职状态列表
				jobStatuslist:[
					   {
							value: '1',
							label: '积极求职中'
						},
						{
							value: '2',
							label: '已有Offer,停止求职'
						},
						{
							value: '3',
							label: '没有Offer,暂不求职'
						}
				],
				//显示求职状态
				jobStatus:'',
				//用户id
				_id:'',
			}
			
		},
		onLoad() {
		// console.log(this.username)
		},
		methods: {
			
			//跳转并相关热门岗位
			enterLogin(){
				// console.log(uni.getStorageSync('storage_user'))
				//用户登录就不能再次登录了
				if(uni.getStorageSync('storage_user')!='') return;
				uni.navigateTo({
				   url:'/pages/user/login'
				 })
			},
			//退出登录提示框
			signOut(){
				//用户未登录返回
				if(!uni.getStorageSync('storage_user')!='') return;
				this.show=true;
			},
			//确认退出
			confirm() {
				// console.log("确认退出")
				uni.removeStorageSync('storage_user')
				// console.log(this.username)
				this.real_name='未登录/注册',
				// username:'safd'
				this.welcome='点击头像进行登录或者注册'
				this.pic='../../static/icon/KHCFDC_头像 2.png'
				this.jobStatus=''
			},
			enterSetMyself(){
				//跳转的个人设置页
				uni.navigateTo({
				   url:'/pages/setMyself/setMyself'
				 })
			},
			enterCollection(){
				//跳转的收藏页
				uni.navigateTo({
				   url:'/pages/collection/collection'
				 })
			},
			enterIdea(){
				//跳转的意见反馈页
				uni.navigateTo({
				   url:'/pages/idea/idea'
				 })
			},
			enterDeliveryFeedback(){
				//跳转的投递反馈页
				uni.navigateTo({
				   url:'/pages/deliveryFeedback/deliveryFeedback'
				 })
			},
			enterResume(){
				//跳转进求职简历页/上传附件页
				uni.navigateTo({
					url:'/pages/resume/resume'
				})
				
			}, 
			enterMyResume(){
				//跳转进我的简历列表页
				uni.navigateTo({
					url:'/pages/myResume/myResume'
				})
				
			}, 
			//修改用户求职状态
			changeJobState(){
				// console.log(this.jobStatus)
				uniCloud.callFunction({
								name: "user",
								data: {
									_id:this._id,
									job_state:this.jobStatus,
									type: "changeUserJobState"
								},
								success: (res) => {
									// console.log("error！",res);
									console.log()
									if(res.result.upObj.updated!=1){
										// console.log("error！",res);
										//失败 提示消息
										this.$refs.uToast.show({
												title: "求职状态修改失败！",
												type: 'info',//提示文字
												position:"top",
												duration:'1000',//时间
												icon:false
												})
										return;
									}
									//更改本地款存数据
									uni.setStorageSync("storage_user",res.result.user)
									//成功
									//提示消息
									this.$refs.uToast.show({
											title: "求职状态修改成功！",
											type: 'success',//提示文字
											position:"top",
											icon:false,
											duration:'1000',//时间
											})
					
								},
								fail: (err) => {
									console.log(err)
								}
							})
							
					
			},
			//监听求职状态改变确认
			jobStatusSelectShowConfirm(e){
				this.jobStatus=e[0].label
				this.changeJobState();
				
			}
			
		},
		//页面生命周期
		//首次加载
		onLaunch: function() {
			// console.log(uni.getStorageSync('storage_user'));
			// console.log(this._id);
		},
		//显示
		onShow: function() {
			// console.log("onShow");
			// console.log(uni.getStorageSync('storage_user'));
				//每次显示更新数据
				this.real_name=uni.getStorageSync('storage_user')!=''?uni.getStorageSync('storage_user').data[0].real_name:'未登录/注册';
				this.welcome=uni.getStorageSync('storage_user')!=''?'欢迎登录校园招聘':'点击头像进行登录或者注册'
				this.pic=uni.getStorageSync('storage_user')!=''?`${uni.getStorageSync('storage_user').data[0].head_image}`:'../../static/icon/KHCFDC_头像 2.png'
				this.jobStatus=uni.getStorageSync('storage_user')!=''?uni.getStorageSync('storage_user').data[0].job_state:''
				this._id=uni.getStorageSync('storage_user')!=''?uni.getStorageSync('storage_user').data[0]._id:'';
		},
		//隐藏
		onHide: function() {
			// console.log("onHide")
		},
		
	}
</script>

<style lang="scss">
page{
	background-color: #ededed;
}

.camera{
	width: 54px;
	height: 44px;
	
	&:active{
		background-color: #ededed;
	}
}
.user-box{
	background-color: #2979ff ;
	color: #fff;
}
.signOut{
	color: #909399 !important;
	margin-top: 20rpx;
	text-align: center;
}
</style>
